package com.ase.springsecurity.controller;

import com.ase.springsecurity.entity.mongodb.UserMongoDB;
import com.ase.springsecurity.result.Result;
import com.ase.springsecurity.service.UserMongoDBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gyhstart
 * @create 2020/12/27 - 13:17
 **/

@RestController
@RequestMapping("/mongodb")
public class UserMongoDBController {

    @Autowired
    private UserMongoDBService userMongoDBService;

    /**
     * MongoDB 增加
     * @param userMongoDB
     */
    @PostMapping("/saveMongoDB")
    public Result saveMongoDB(@RequestBody UserMongoDB userMongoDB){
        int userMongoDBResult = userMongoDBService.saveMongoDB(userMongoDB);
        return Result.success(userMongoDBResult);
    }

    /**
     * MongoDB 删除
     * @param id
     */
    @DeleteMapping("/removeMongoDB")
    public void removeMongoDB(@RequestParam("id") int id){
       userMongoDBService.removeMongoDB(id);
    }

    /**
     * MongoDB 修改
     * @param userMongoDB
     */
    @PutMapping("/modifyMongoDB")
    public void updateMongoDB(@RequestBody UserMongoDB userMongoDB){
        userMongoDBService.updateMongoDB(userMongoDB);
    }

    /**
     * MongoDB 查询
     * @return
     */
    @GetMapping("/queryMongoDBAll")
    public Result findMongoDB(){
        List<UserMongoDB> mongoDBList = userMongoDBService.findMongoDB();
        return Result.success(mongoDBList);
    }
}
